FROM node:lts-alpine
WORKDIR /opt/build
ADD assets/package.json .
RUN yarn install --registry=https://registry.npm.taobao.org --no-lockfile
ADD assets .
RUN set -ex&&yarn build

FROM golang:1.15-buster
WORKDIR /opt/build
COPY --from=0 /opt/build/build ./build
ADD go.mod .
RUN set -ex&&export GO111MODULE=on&&export GOSUMDB=off&&export GOPROXY=https://goproxy.cn&&go mod download&&go get github.com/rakyll/statik
RUN rm -rf statik&&statik -src=build/  -include=*.html,*.js,*.json,*.css,*.png,*.svg,*.ico,*.ttf -f
ADD . .
RUN set -ex&&export GO111MODULE=on&&export GOSUMDB=off&&export GOPROXY=https://goproxy.cn&&go build -o agent .

FROM errort/alpine-glibc:3.12
WORKDIR /opt/agent
COPY --from=1 /opt/build/agent agent
COPY start.sh .
RUN set -ex&&chmod +x start.sh&&chmod +x agent
ENTRYPOINT ["sh","-c","/opt/agent/start.sh"]